from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, BooleanField, SelectField, PasswordField
from wtforms.validators import DataRequired, Length, Email, Optional, URL
from wtforms.widgets import TextArea

class LoginForm(FlaskForm):
    """登录表单"""
    username = StringField('用户名', validators=[DataRequired(), Length(1, 80)])
    password = PasswordField('密码', validators=[DataRequired()])
    remember_me = BooleanField('记住我')

class PostForm(FlaskForm):
    """文章表单"""
    title = StringField('标题', validators=[DataRequired(), Length(1, 200)])
    content = TextAreaField('内容', validators=[DataRequired()], 
                           widget=TextArea(), render_kw={'rows': 20})
    excerpt = TextAreaField('摘要', validators=[Optional(), Length(0, 500)],
                           widget=TextArea(), render_kw={'rows': 3})
    tags = StringField('标签', validators=[Optional()], 
                      render_kw={'placeholder': '用逗号分隔多个标签'})
    category_id = SelectField('分类', coerce=int, validators=[Optional()])
    is_published = BooleanField('发布')
    is_featured = BooleanField('推荐')

class CommentForm(FlaskForm):
    """评论表单"""
    name = StringField('姓名', validators=[DataRequired(), Length(1, 80)])
    email = StringField('邮箱', validators=[DataRequired(), Email(), Length(1, 120)])
    website = StringField('网站', validators=[Optional(), URL(), Length(0, 200)],
                         render_kw={'placeholder': 'http://example.com'})
    content = TextAreaField('评论内容', validators=[DataRequired(), Length(1, 1000)],
                           widget=TextArea(), render_kw={'rows': 4})

class CategoryForm(FlaskForm):
    """分类表单"""
    name = StringField('分类名称', validators=[DataRequired(), Length(1, 50)])
    description = TextAreaField('描述', validators=[Optional(), Length(0, 500)],
                               widget=TextArea(), render_kw={'rows': 3})

class TagForm(FlaskForm):
    """标签表单"""
    name = StringField('标签名称', validators=[DataRequired(), Length(1, 30)])

